﻿// See https://aka.ms/new-console-template for more information
using ConsoleES;
using Nest;
using SqlSugar;
using System.Drawing.Printing;

Console.WriteLine("Hello, World!");

var sqlSugar = SqlSugarHelper.GetInstance();

var settings = new ConnectionSettings(new Uri("https://192.168.0.250:9200"))
    .BasicAuthentication("elastic","12345678")
    .DefaultIndex("badun06_model_test"); // 指定默认的索引名称

var client = new ElasticClient(settings);

RefAsync<int> total = 0;//REF和OUT不支持异步,想要真的异步这是最优解
int pagenumber = 1; // pagenumber是从1开始的不是从零开始的
int pageSize = 1000;
List<ESLabelModel> eSLabels = await sqlSugar.Queryable<ESLabelModel>().ToPageListAsync(pagenumber, pageSize, total);//ToPageAsync
int pageTotal = total / pageSize;
await Console.Out.WriteLineAsync($"总数:{total},总页数:{pageTotal},count={}");
for (int i = pagenumber; i < pageTotal; pagenumber++)
{
    eSLabels = await sqlSugar.Queryable<ESLabelModel>().ToPageListAsync(pagenumber, pageSize, total);
    foreach (var item in eSLabels)
    {
        var indexResponse = await client.IndexDocumentAsync(item);
        if (indexResponse.IsValid)
        {
            await Console.Out.WriteLineAsync($"{item.Id},{item.CurrentDatetime},{item.NowDatetime}");
        }
        else
        {
            Console.WriteLine($"Failed to index document: {indexResponse.DebugInformation}");
        }
    }
}




[SugarTable("badun06_tb")]
public class ESLabelModel
{
    /// <summary>
    /// 服务器时间戳
    /// </summary>
    [SugarColumn(ColumnName = "now_datetime", IsNullable = true)]
    public long NowDatetime { get; set; }

    /// <summary>
    /// 当前时间(由时间戳转换)
    /// </summary>
    [SugarColumn(ColumnName = "current_datetime", IsNullable = true)]
    public string CurrentDatetime { get; set; }

    /// <summary>
    /// 是否有异常
    /// </summary>
    [SugarColumn(ColumnName = "has_abnormal", IsNullable = false)]
    public bool HasAnormal { get; set; }

    /// <summary>
    /// GUID - 唯一ID
    /// </summary>
    [SugarColumn(IsPrimaryKey = true, ColumnName = "id", IsNullable = false)]
    public string Id { get; set; }

    #region value

    /// <summary>
    /// 挤出机转速 [m/min]
    /// </summary>
    [SugarColumn(ColumnName = "main_speed", IsNullable = true)]
    public float? MainSpeed { get; set; }

    /// <summary>
    /// 挤出机扭矩 [%]
    /// </summary>
    [SugarColumn(ColumnName = "main_torque", IsNullable = true)]
    public float? MainTorque { get; set; }

    /// <summary>
    /// 变速箱温度 [℃]
    /// </summary>
    [SugarColumn(ColumnName = "gearbox_temp", IsNullable = true)]
    public float? GearboxTemp { get; set; }

    /// <summary>
    /// 熔体挤出量 [kg/h]
    /// </summary>
    [SugarColumn(ColumnName = "extrusion", IsNullable = true)]
    public float? Extrusion { get; set; }

    /// <summary>
    /// 挤出机机筒温度1 [℃]
    /// </summary>
    [SugarColumn(ColumnName = "barrel_temp1", IsNullable = true)]
    public float? BarrelTemp1 { get; set; }

    /// <summary>
    /// 挤出机机筒温度2 [℃]
    /// </summary>
    [SugarColumn(ColumnName = "barrel_temp2", IsNullable = true)]
    public float? BarrelTemp2 { get; set; }

    /// <summary>
    /// 挤出机机筒温度3 [℃]
    /// </summary>
    [SugarColumn(ColumnName = "barrel_temp3", IsNullable = true)]
    public float? BarrelTemp3 { get; set; }

    /// <summary>
    /// 挤出机机筒温度4 [℃]
    /// </summary>
    [SugarColumn(ColumnName = "barrel_temp4", IsNullable = true)]
    public float? BarrelTemp4 { get; set; }

    /// <summary>
    /// 挤出机机筒温度5 [℃]
    /// </summary>
    [SugarColumn(ColumnName = "barrel_temp5", IsNullable = true)]
    public float? BarrelTemp5 { get; set; }

    /// <summary>
    /// 主机熔体温度 [℃]
    /// </summary>
    [SugarColumn(ColumnName = "main_melt_temp", IsNullable = true)]
    public float? MainMeltTemp { get; set; }

    /// <summary>
    /// 主机熔体压力 [bar]
    /// </summary>
    [SugarColumn(ColumnName = "main_melt_press", IsNullable = true)]
    public float? MainMeltPress { get; set; }

    /// <summary>
    /// 连接体温度 [℃]
    /// </summary>
    [SugarColumn(ColumnName = "junction_temp", IsNullable = true)]
    public float? JunctionTemp { get; set; }

    /// <summary>
    /// 芯模温度1 [℃]
    /// </summary>
    [SugarColumn(ColumnName = "main_stage_temp1", IsNullable = true)]
    public float? MainStageTemp1 { get; set; }

    /// <summary>
    /// 芯模温度2 [℃]
    /// </summary>
    [SugarColumn(ColumnName = "main_stage_temp2", IsNullable = true)]
    public float? MainStageTemp2 { get; set; }

    /// <summary>
    /// 模头温度1 [℃]
    /// </summary>
    [SugarColumn(ColumnName = "main_stage_temp3", IsNullable = true)]
    public float? MainStageTemp3 { get; set; }

    /// <summary>
    /// 模头温度2 [℃]
    /// </summary>
    [SugarColumn(ColumnName = "main_stage_temp4", IsNullable = true)]
    public float? MainStageTemp4 { get; set; }

    /// <summary>
    /// 模头温度3 [℃]
    /// </summary>
    [SugarColumn(ColumnName = "main_stage_temp5", IsNullable = true)]
    public float? MainStageTemp5 { get; set; }

    /// <summary>
    /// 模头温度4 [℃]
    /// </summary>
    [SugarColumn(ColumnName = "main_stage_temp6", IsNullable = true)]
    public float? MainStageTemp6 { get; set; }

    /// <summary>
    /// 模头温度5 [℃]
    /// </summary>
    [SugarColumn(ColumnName = "main_stage_temp7", IsNullable = true)]
    public float? MainStageTemp7 { get; set; }

    /// <summary>
    /// 标色机转速 [m/min]
    /// </summary>
    [SugarColumn(ColumnName = "color_mach_main_speed", IsNullable = true)]
    public float? ColorMachMainSpeed { get; set; }

    /// <summary>
    /// 标色机扭矩 [%]
    /// </summary>
    [SugarColumn(ColumnName = "color_mach_main_torque", IsNullable = true)]
    public float? ColorMachMainTorque { get; set; }

    /// <summary>
    /// 标色机机筒温度1 [℃]
    /// </summary>
    [SugarColumn(ColumnName = "color_mach_barrel_temp1", IsNullable = true)]
    public float? ColorMachBarrelTemp1 { get; set; }

    /// <summary>
    /// 标色机机筒温度2 [℃]
    /// </summary>
    [SugarColumn(ColumnName = "color_mach_barrel_temp2", IsNullable = true)]
    public float? ColorMachBarrelTemp2 { get; set; }

    /// <summary>
    /// 标色机机筒温度3 [℃]
    /// </summary>
    [SugarColumn(ColumnName = "color_mach_barrel_temp3", IsNullable = true)]
    public float? ColorMachBarrelTemp3 { get; set; }

    /// <summary>
    /// 标色机熔体压力 [bar]
    /// </summary>
    [SugarColumn(ColumnName = "color_mach_melt_press", IsNullable = true)]
    public float? ColorMachMeltPress { get; set; }

    /// <summary>
    /// 标色机熔体温度 [℃]
    /// </summary>
    [SugarColumn(ColumnName = "color_mach_melt_temp", IsNullable = true)]
    public float? ColorMachMeltTemp { get; set; }

    /// <summary>
    /// 牵引机转速 [m/min]
    /// </summary>
    [SugarColumn(ColumnName = "tractor_main_speed", IsNullable = true)]
    public float? TractorMainSpeed { get; set; }

    /// <summary>
    /// 牵引机扭矩 [%]
    /// </summary>
    [SugarColumn(ColumnName = "tractor_main_torque", IsNullable = true)]
    public float? TractorMainTorque { get; set; }

    /// <summary>
    /// 牵引机牵引速度 [m/min]
    /// </summary>
    [SugarColumn(ColumnName = "tractor_traction_speed", IsNullable = true)]
    public float? TractorTractionSpeed { get; set; }

    /// <summary>
    /// 切割机切割长度 [m]
    /// </summary>
    [SugarColumn(ColumnName = "cut_mach_cut_len", IsNullable = true)]
    public float? CutMachCutLen { get; set; }

    /// <summary>
    /// 1段真空度 [bar]
    /// </summary>
    [SugarColumn(ColumnName = "vacuum1_vacuum", IsNullable = true)]
    public float? Vacuum1Vacuum { get; set; }

    /// <summary>
    /// 1段水温 [℃]
    /// </summary>
    [SugarColumn(ColumnName = "vacuum1_water_temp", IsNullable = true)]
    public float? Vacuum1WaterTemp { get; set; }

    /// <summary>
    /// 1段过滤前水压 [bar]
    /// </summary>
    [SugarColumn(ColumnName = "vacuum1_filter1_water_pres", IsNullable = true)]
    public float? Vacuum1Filter1WaterPres { get; set; }

    /// <summary>
    /// 1段过滤后水压 [bar]
    /// </summary>
    [SugarColumn(ColumnName = "vacuum1_filter2_water_pres", IsNullable = true)]
    public float? Vacuum1Filter2WaterPres { get; set; }

    /// <summary>
    /// 2段真空度 [bar]
    /// </summary>
    [SugarColumn(ColumnName = "vacuum2_vacuum", IsNullable = true)]
    public float? Vacuum2Vacuum { get; set; }

    /// <summary>
    /// 2段水温 [℃]
    /// </summary>
    [SugarColumn(ColumnName = "vacuum2_water_temp", IsNullable = true)]
    public float? Vacuum2WaterTemp { get; set; }

    /// <summary>
    /// 2段过滤前水压 [bar]
    /// </summary>
    [SugarColumn(ColumnName = "vacuum2_filter1_water_pres", IsNullable = true)]
    public float? Vacuum2Filter1WaterPres { get; set; }

    /// <summary>
    /// 2段过滤后水压 [bar]
    /// </summary>
    [SugarColumn(ColumnName = "vacuum2_filter2_water_pres", IsNullable = true)]
    public float? Vacuum2Filter2WaterPres { get; set; }

    /// <summary>
    /// 3段水温 [℃]
    /// </summary>
    [SugarColumn(ColumnName = "cooler3_water_temp", IsNullable = true)]
    public float? Cooler3WaterTemp { get; set; }

    /// <summary>
    /// 牵引机总气压 [bar]
    /// </summary>
    [SugarColumn(ColumnName = "tractor_total_pressure", IsNullable = true)]
    public float? TractorTotalPressure { get; set; }

    /// <summary>
    /// 切割机总气压 [bar]
    /// </summary>
    [SugarColumn(ColumnName = "cutter_total_pressure", IsNullable = true)]
    public float? CutterTotalPressure { get; set; }

    #endregion
}